/*
 * 版权所有 Amor. 保留所有权利。
 * 根据 MIT 许可证条款分发。
 *
 * 作者： amor
 *		Ant Design 实现
 */

/*! AntControlLook - Haiku 的 Ant Design 5.0 风格 */

#include "AntControlLook.h"

#include <ControlLook.h>
#include <GradientLinear.h>
#include <Rect.h>
#include <Region.h>
#include <View.h>
#include <WindowPrivate.h>
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <new>

namespace BPrivate {

// Ant Design 5.0 特定的UI常量定义
// 这些常量用于控制Ant Design风格UI元素的视觉表现

// 边框高亮部分的色调值（1.0表示不改变原色）
static const float kEdgeBevelLightTint = 1.0;
// 边框阴影部分的色调值（1.0表示不改变原色）
static const float kEdgeBevelShadowTint = 1.0;
// 鼠标悬停时的色调变化因子（0.55表示轻微变亮）
static const float kHoverTintFactor = 0.55;

// 按钮弹出指示器的宽度（11像素）
static const float kButtonPopUpIndicatorWidth = 11;

// Ant Design 5 色彩系统常量定义

// 品牌色梯度（蓝色）
const rgb_color AntControlLook::kAntPrimaryColors[10] = {
  {230, 247, 255}, // 蓝色-1
  {186, 231, 255}, // 蓝色-2
  {145, 213, 255}, // 蓝色-3
  {105, 192, 255}, // 蓝色-4
  {64, 169, 255},  // 蓝色-5
  {24, 144, 255},  // 蓝色-6（主色）
  {9, 109, 217},   // 蓝色-7
  {0, 80, 179},    // 蓝色-8
  {0, 58, 140},    // 蓝色-9
  {0, 39, 102}     // 蓝色-10
};

// 成功色梯度（绿色）
const rgb_color AntControlLook::kAntSuccessColors[10] = {
  {246, 255, 237}, // 绿色-1
  {217, 247, 190}, // 绿色-2
  {183, 235, 143}, // 绿色-3
  {149, 222, 100}, // 绿色-4
  {115, 209, 61},  // 绿色-5
  {82, 196, 26},   // 绿色-6（主色）
  {56, 158, 13},   // 绿色-7
  {35, 120, 4},    // 绿色-8
  {19, 82, 0},     // 绿色-9
  {9, 43, 0}       // 绿色-10
};

// 警告色梯度（金色）
const rgb_color AntControlLook::kAntWarningColors[10] = {
  {255, 247, 230}, // 金色-1
  {255, 231, 186}, // 金色-2
  {255, 213, 145}, // 金色-3
  {255, 192, 105}, // 金色-4
  {255, 169, 64},  // 金色-5
  {250, 173, 20},  // 金色-6（主色）
  {212, 136, 6},   // 金色-7
  {173, 104, 0},   // 金色-8
  {135, 77, 0},    // 金色-9
  {97, 52, 0}      // 金色-10
};

// 错误色梯度（红色）
const rgb_color AntControlLook::kAntErrorColors[10] = {
  {255, 241, 240}, // 红色-1
  {255, 204, 199}, // 红色-2
  {255, 163, 158}, // 红色-3
  {255, 120, 117}, // 红色-4
  {255, 77, 79},   // 红色-5
  {245, 34, 45},   // 红色-6（主色）
  {207, 19, 34},   // 红色-7
  {168, 7, 26},    // 红色-8
  {130, 0, 20},    // 红色-9
  {92, 0, 17}      // 红色-10
};

// 中性色
const rgb_color AntControlLook::kAntTextPrimary = {0, 0, 0, 217};      // 85%黑
const rgb_color AntControlLook::kAntTextSecondary = {0, 0, 0, 166};    // 65%黑
const rgb_color AntControlLook::kAntTextDisabled = {0, 0, 0, 115};     // 45%黑
const rgb_color AntControlLook::kAntBorder = {217, 217, 217};          // #D9D9D9
const rgb_color AntControlLook::kAntBackground = {245, 245, 245};      // #F5F5F5
const rgb_color AntControlLook::kAntTableHeader = {250, 250, 250};     // #FAFAFA

// 暗色主题色彩
const rgb_color AntControlLook::kAntDarkBackground = {20, 20, 20};     // #141414
const rgb_color AntControlLook::kAntDarkComponentBg = {31, 31, 31};     // #1F1F1F
const rgb_color AntControlLook::kAntDarkSecondaryBg = {38, 38, 38};     // #262626
const rgb_color AntControlLook::kAntDarkBorder = {67, 67, 67};          // #434343
const rgb_color AntControlLook::kAntDarkTextPrimary = {255, 255, 255, 217};    // 85%白
const rgb_color AntControlLook::kAntDarkTextSecondary = {255, 255, 255, 166};  // 65%白
const rgb_color AntControlLook::kAntDarkTextDisabled = {255, 255, 255, 115};   // 45%白

// 构造函数 - 继承HaikuControlLook基类，初始化为亮色主题
AntControlLook::AntControlLook() 
  : HaikuControlLook(),
    fThemeMode(LIGHT) {}

// 析构函数
AntControlLook::~AntControlLook() {}

// #pragma mark - Ant Design 5 色彩系统实现

// 获取品牌色
rgb_color AntControlLook::GetPrimaryColor(int level) const {
  // 确保level在有效范围内
  level = std::max(1, std::min(level, 10));
  
  // 返回对应级别的颜色
  return kAntPrimaryColors[level - 1];
}

// 获取成功色
rgb_color AntControlLook::GetSuccessColor(int level) const {
  level = std::max(1, std::min(level, 10));
  return kAntSuccessColors[level - 1];
}

// 获取警告色
rgb_color AntControlLook::GetWarningColor(int level) const {
  level = std::max(1, std::min(level, 10));
  return kAntWarningColors[level - 1];
}

// 获取错误色
rgb_color AntControlLook::GetErrorColor(int level) const {
  level = std::max(1, std::min(level, 10));
  return kAntErrorColors[level - 1];
}

// 获取文本色
rgb_color AntControlLook::GetTextPrimaryColor() const {
  return fThemeMode == LIGHT ? kAntTextPrimary : kAntDarkTextPrimary;
}

rgb_color AntControlLook::GetTextSecondaryColor() const {
  return fThemeMode == LIGHT ? kAntTextSecondary : kAntDarkTextSecondary;
}

rgb_color AntControlLook::GetTextDisabledColor() const {
  return fThemeMode == LIGHT ? kAntTextDisabled : kAntDarkTextDisabled;
}

// 获取边框色
rgb_color AntControlLook::GetBorderColor() const {
  return fThemeMode == LIGHT ? kAntBorder : kAntDarkBorder;
}

// 获取背景色
rgb_color AntControlLook::GetBackgroundColor() const {
  return fThemeMode == LIGHT ? kAntBackground : kAntDarkBackground;
}

rgb_color AntControlLook::GetTableHeaderColor() const {
  return fThemeMode == LIGHT ? kAntTableHeader : kAntDarkSecondaryBg;
}

// 设置主题模式
void AntControlLook::SetThemeMode(ThemeMode mode) {
  fThemeMode = mode;
}

// 获取当前主题模式
AntControlLook::ThemeMode AntControlLook::GetThemeMode() const {
  return fThemeMode;
}

// 获取悬停状态的颜色
rgb_color AntControlLook::GetHoverColor(const rgb_color& base) const {
  // 使颜色更亮
  rgb_color hover = base;
  hover.red = std::min(255, (int)(base.red * 1.1));
  hover.green = std::min(255, (int)(base.green * 1.1));
  hover.blue = std::min(255, (int)(base.blue * 1.1));
  return hover;
}

// 获取激活状态的颜色
rgb_color AntControlLook::GetActiveColor(const rgb_color& base) const {
  // 使颜色更暗
  rgb_color active = base;
  active.red = (int)(base.red * 0.9);
  active.green = (int)(base.green * 0.9);
  active.blue = (int)(base.blue * 0.9);
  return active;
}

// 获取禁用状态的颜色
rgb_color AntControlLook::GetDisabledColor(const rgb_color& base) const {
  // 降低饱和度并增加亮度
  rgb_color disabled = base;
  
  // 计算灰度值
  int gray = (int)(base.red * 0.3 + base.green * 0.59 + base.blue * 0.11);
  
  // 向灰色过渡
  disabled.red = (int)(base.red * 0.5 + gray * 0.5);
  disabled.green = (int)(base.green * 0.5 + gray * 0.5);
  disabled.blue = (int)(base.blue * 0.5 + gray * 0.5);
  
  return disabled;
}

// 获取对比色
rgb_color AntControlLook::GetContrastColor(const rgb_color& background) const {
  // 计算亮度
  int brightness = (int)(background.red * 0.299 + background.green * 0.587 + background.blue * 0.114);
  
  // 亮度高于128使用黑色文本，否则使用白色文本
  if (brightness > 128) {
    return fThemeMode == LIGHT ? kAntTextPrimary : (rgb_color){0, 0, 0, 255};
  } else {
    return fThemeMode == LIGHT ? (rgb_color){255, 255, 255, 255} : kAntDarkTextPrimary;
  }
}

// #pragma mark - Ant Design 5 色彩系统应用示例

// 绘制主要按钮
void AntControlLook::DrawPrimaryButton(BView* view, BRect& rect,
                                      const BRect& updateRect,
                                      const rgb_color& base,
                                      uint32 flags,
                                      const char* text,
                                      const BBitmap* icon) {
  // 检查是否需要绘制
  if (!ShouldDraw(view, rect, updateRect))
    return;
    
  // 保存原始矩形，用于按下效果
  BRect originalRect = rect;
  
  // 确定按钮背景色
  rgb_color backgroundColor;
  
  if (flags & B_DISABLED) {
    // 禁用状态
    backgroundColor = GetDisabledColor(GetPrimaryColor());
  } else if (flags & B_CLICKED) {
    // 点击状态
    backgroundColor = GetActiveColor(GetPrimaryColor());
    // 按钮按下效果 - 轻微下移
    rect.OffsetBy(0, 1);
  } else if (flags & B_HOVER) {
    // 悬停状态
    backgroundColor = GetHoverColor(GetPrimaryColor());
  } else {
    // 默认状态
    backgroundColor = GetPrimaryColor();
  }
  
  // 设置绘图颜色
  view->SetHighColor(backgroundColor);
  
  // 绘制圆角矩形
  view->FillRoundRect(rect, kRadius, kRadius);
  
  // 确定文本颜色（主按钮通常使用白色文本）
  rgb_color textColor = {255, 255, 255, 255};
  if (flags & B_DISABLED) {
    textColor.alpha = 128; // 半透明
  }
  
  // 如果有文本需要绘制
  if (text != NULL && text[0] != '\0') {
    // 保存当前字体状态
    font_height fontHeight;
    view->GetFontHeight(&fontHeight);
    
    // 计算文本宽度
    float textWidth = view->StringWidth(text);
    float textHeight = fontHeight.ascent + fontHeight.descent;
    
    // 计算文本位置（居中）
    float x, y;
    
    // 如果有图标，调整文本位置
    if (icon != NULL) {
      // 图标和文本的间距
      float spacing = 8.0f;
      float iconWidth = icon->Bounds().Width();
      float totalWidth = iconWidth + spacing + textWidth;
      
      // 计算起始x位置（整体居中）
      x = rect.left + (rect.Width() - totalWidth) / 2.0f + iconWidth + spacing;
      
      // 绘制图标
      view->SetDrawingMode(B_OP_ALPHA);
      view->DrawBitmap(icon, BPoint(rect.left + (rect.Width() - totalWidth) / 2.0f,
                                   rect.top + (rect.Height() - icon->Bounds().Height()) / 2.0f));
      view->SetDrawingMode(B_OP_COPY);
    } else {
      // 无图标，文本水平居中
      x = rect.left + (rect.Width() - textWidth) / 2.0f;
    }
    
    // 文本垂直居中
    y = rect.top + (rect.Height() - textHeight) / 2.0f + fontHeight.ascent;
    
    // 设置文本颜色并绘制
    view->SetHighColor(textColor);
    view->SetLowColor(backgroundColor);
    view->DrawString(text, BPoint(x, y));
  } else if (icon != NULL) {
    // 只有图标，无文本
    view->SetDrawingMode(B_OP_ALPHA);
    view->DrawBitmap(icon, BPoint(rect.left + (rect.Width() - icon->Bounds().Width()) / 2.0f,
                                 rect.top + (rect.Height() - icon->Bounds().Height()) / 2.0f));
    view->SetDrawingMode(B_OP_COPY);
  }
  
  // 恢复原始矩形
  rect = originalRect;
}

// 绘制次要按钮
void AntControlLook::DrawSecondaryButton(BView* view, BRect& rect,
                                        const BRect& updateRect,
                                        const rgb_color& base,
                                        uint32 flags,
                                        const char* text,
                                        const BBitmap* icon) {
  // 检查是否需要绘制
  if (!ShouldDraw(view, rect, updateRect))
    return;
    
  // 保存原始矩形，用于按下效果
  BRect originalRect = rect;
  
  // 确定按钮背景色（次要按钮通常使用白色背景）
  rgb_color backgroundColor = {255, 255, 255, 255};
  
  // 确定边框颜色
  rgb_color borderColor;
  if (flags & B_DISABLED) {
    borderColor = GetDisabledColor(GetBorderColor());
  } else if (flags & B_CLICKED) {
    borderColor = GetActiveColor(GetPrimaryColor());
    // 按钮按下效果 - 轻微下移
    rect.OffsetBy(0, 1);
  } else if (flags & B_HOVER) {
    borderColor = GetHoverColor(GetPrimaryColor());
  } else {
    borderColor = GetBorderColor();
  }
  
  // 设置绘图颜色
  view->SetHighColor(backgroundColor);
  
  // 绘制圆角矩形
  view->FillRoundRect(rect, kRadius, kRadius);
  
  // 绘制边框
  view->SetHighColor(borderColor);
  view->StrokeRoundRect(rect, kRadius, kRadius);
  
  // 确定文本颜色
  rgb_color textColor;
  if (flags & B_DISABLED) {
    textColor = GetTextDisabledColor();
  } else if (flags & B_CLICKED || flags & B_HOVER) {
    textColor = GetPrimaryColor();
  } else {
    textColor = GetTextPrimaryColor();
  }
  
  // 如果有文本需要绘制
  if (text != NULL && text[0] != '\0') {
    // 保存当前字体状态
    font_height fontHeight;
    view->GetFontHeight(&fontHeight);
    
    // 计算文本宽度
    float textWidth = view->StringWidth(text);
    float textHeight = fontHeight.ascent + fontHeight.descent;
    
    // 计算文本位置（居中）
    float x, y;
    
    // 如果有图标，调整文本位置
    if (icon != NULL) {
      // 图标和文本的间距
      float spacing = 8.0f;
      float iconWidth = icon->Bounds().Width();
      float totalWidth = iconWidth + spacing + textWidth;
      
      // 计算起始x位置（整体居中）
      x = rect.left + (rect.Width() - totalWidth) / 2.0f + iconWidth + spacing;
      
      // 绘制图标
      view->SetDrawingMode(B_OP_ALPHA);
      view->DrawBitmap(icon, BPoint(rect.left + (rect.Width() - totalWidth) / 2.0f,
                                   rect.top + (rect.Height() - icon->Bounds().Height()) / 2.0f));
      view->SetDrawingMode(B_OP_COPY);
    } else {
      // 无图标，文本水平居中
      x = rect.left + (rect.Width() - textWidth) / 2.0f;
    }
    
    // 文本垂直居中
    y = rect.top + (rect.Height() - textHeight) / 2.0f + fontHeight.ascent;
    
    // 设置文本颜色并绘制
    view->SetHighColor(textColor);
    view->SetLowColor(backgroundColor);
    view->DrawString(text, BPoint(x, y));
  } else if (icon != NULL) {
    // 只有图标，无文本
    view->SetDrawingMode(B_OP_ALPHA);
    view->DrawBitmap(icon, BPoint(rect.left + (rect.Width() - icon->Bounds().Width()) / 2.0f,
                                 rect.top + (rect.Height() - icon->Bounds().Height()) / 2.0f));
    view->SetDrawingMode(B_OP_COPY);
  }
  
  // 恢复原始矩形
  rect = originalRect;
}

// 绘制输入框
void AntControlLook::DrawTextInput(BView* view, BRect& rect,
                                  const BRect& updateRect,
                                  const rgb_color& base,
                                  uint32 flags) {
  // 确定背景色
  rgb_color backgroundColor = {255, 255, 255, 255};
  
  // 确定边框颜色
  rgb_color borderColor;
  if (flags & B_DISABLED) {
    borderColor = GetDisabledColor(GetBorderColor());
  } else if (flags & B_FOCUSED) {
    borderColor = GetPrimaryColor();
  } else if (flags & B_HOVER) {
    borderColor = GetHoverColor(GetBorderColor());
  } else {
    borderColor = GetBorderColor();
  }
  
  // 设置绘图颜色
  view->SetHighColor(backgroundColor);
  
  // 绘制圆角矩形
  view->FillRoundRect(rect, kRadius, kRadius);
  
  // 绘制边框
  view->SetHighColor(borderColor);
  view->StrokeRoundRect(rect, kRadius, kRadius);
  
  // 如果是聚焦状态，绘制阴影效果
  if (flags & B_FOCUSED) {
    view->SetHighColor(tint_color(GetPrimaryColor(), B_LIGHTEN_2_TINT));
    view->SetPenSize(0.5);
    BRect shadowRect = rect;
    shadowRect.InsetBy(-2, -2);
    view->StrokeRoundRect(shadowRect, kRadius + 2, kRadius + 2);
    view->SetPenSize(1.0);
  }
}

// #pragma mark -

// 绘制按钮边框的基础方法
// 使用默认圆角半径(kRadius)绘制Ant Design风格的按钮边框
// 参数:
//   view - 绘制目标视图
//   rect - 按钮的矩形区域(会被修改)
//   updateRect - 需要更新的区域
//   base - 基础颜色
//   background - 背景颜色
//   flags - 按钮状态标志(B_DISABLED, B_HOVER等)
//   borders - 需要绘制的边框(B_LEFT_BORDER等)
void AntControlLook::DrawButtonFrame(BView *view, BRect &rect,
                                     const BRect &updateRect,
                                     const rgb_color &base,
                                     const rgb_color &background, uint32 flags,
                                     uint32 borders) {
  // 调用内部实现方法，使用默认圆角半径
  _DrawButtonFrame(view, rect, updateRect, kRadius, kRadius, kRadius, kRadius,
                   base, background, 1.0, 1.0, flags, borders);
}

// 绘制按钮边框的变体方法
// 允许自定义圆角半径，其他参数与基础方法相同
// 参数:
//   radius - 统一的圆角半径
//   其他参数同上
void AntControlLook::DrawButtonFrame(BView *view, BRect &rect,
                                     const BRect &updateRect, float radius,
                                     const rgb_color &base,
                                     const rgb_color &background, uint32 flags,
                                     uint32 borders) {
  // 调用内部实现方法，使用统一的圆角半径
  _DrawButtonFrame(view, rect, updateRect, radius, radius, radius, radius, base,
                   background, 1.0, 1.0, flags, borders);
}

void AntControlLook::DrawButtonFrame(
    BView *view, BRect &rect, const BRect &updateRect, float leftTopRadius,
    float rightTopRadius, float leftBottomRadius, float rightBottomRadius,
    const rgb_color &base, const rgb_color &background, uint32 flags,
    uint32 borders) {
  _DrawButtonFrame(view, rect, updateRect, leftTopRadius, rightTopRadius,
                   leftBottomRadius, rightBottomRadius, base, background, 1.0,
                   1.0, flags, borders);
}

void AntControlLook::DrawButtonBackground(BView *view, BRect &rect,
                                          const BRect &updateRect,
                                          const rgb_color &base, uint32 flags,
                                          uint32 borders,
                                          orientation orientation) {
  _DrawButtonBackground(view, rect, updateRect, kRadius, kRadius, kRadius,
                        kRadius, base, false, flags, borders, orientation);
}

void AntControlLook::DrawButtonBackground(BView *view, BRect &rect,
                                          const BRect &updateRect, float radius,
                                          const rgb_color &base, uint32 flags,
                                          uint32 borders,
                                          orientation orientation) {
  _DrawButtonBackground(view, rect, updateRect, radius, radius, radius, radius,
                        base, false, flags, borders, orientation);
}

void AntControlLook::DrawButtonBackground(
    BView *view, BRect &rect, const BRect &updateRect, float leftTopRadius,
    float rightTopRadius, float leftBottomRadius, float rightBottomRadius,
    const rgb_color &base, uint32 flags, uint32 borders,
    orientation orientation) {
  _DrawButtonBackground(view, rect, updateRect, leftTopRadius, rightTopRadius,
                        leftBottomRadius, rightBottomRadius, base, false, flags,
                        borders, orientation);
}

// 绘制菜单栏背景
// 实现Ant Design风格的菜单栏背景，具有扁平化设计和微妙的阴影效果
// 参数:
//   view - 绘制目标视图
//   rect - 菜单栏矩形区域(会被修改)
//   updateRect - 需要更新的区域
//   base - 基础颜色
//   flags - 状态标志(B_DISABLED禁用状态, B_FOCUSED焦点状态等)
//   borders - 需要绘制的边框(B_TOP_BORDER等)
void AntControlLook::DrawMenuBarBackground(BView *view, BRect &rect,
                                           const BRect &updateRect,
                                           const rgb_color &base, uint32 flags,
                                           uint32 borders) {
  // 检查是否需要绘制，避免不必要的绘制操作
  if (!ShouldDraw(view, rect, updateRect)) return;

  // Ant Design菜单栏使用扁平化设计，带有微妙的阴影效果
  // 定义渐变色调
  float topTint = 1.0;     // 顶部色调值
  float bottomTint = 1.0;  // 底部色调值

  rgb_color customColor = base;                // 使用基础颜色作为起点
  bool isEnabled = (flags & B_DISABLED) == 0;  // 是否启用状态
  bool isFocused = (flags & B_FOCUSED) != 0;   // 是否获得焦点

  if (isEnabled || isFocused) {
    // 启用或获得焦点状态下的颜色处理
    customColor = tint_color(ui_color(B_WINDOW_TAB_COLOR), 1.0);
    rgb_color bevelColor1 = tint_color(customColor, 1.0);  // 斜面颜色1
    rgb_color bevelColor2 = tint_color(customColor, 1.0);  // 斜面颜色2

    topTint = 1.0;
    bottomTint = 1.0;

    // 绘制框架，使用相同的颜色使边框看起来更扁平
    _DrawFrame(view, rect, bevelColor1, bevelColor1, bevelColor2, bevelColor2,
               borders & B_TOP_BORDER);
  } else {
    // 禁用状态下的颜色处理
    rgb_color cornerColor = tint_color(customColor, 1.0);    // 角落颜色
    rgb_color bevelColorTop = tint_color(customColor, 1.0);  // 顶部斜面颜色
    rgb_color bevelColorLeft = tint_color(customColor, 1.0);  // 左侧斜面颜色
    rgb_color bevelColorRightBottom =
        tint_color(customColor, 1.0);  // 右下方斜面颜色

    topTint = 1.0;
    bottomTint = 1.0;

    // 绘制框架，使用相同的颜色使边框看起来更扁平
    _DrawFrame(view, rect, bevelColorLeft, bevelColorTop, bevelColorRightBottom,
               bevelColorRightBottom, cornerColor, cornerColor, borders);
  }

  // 绘制顶部表面，使用渐变填充
  _FillGradient(view, rect, customColor, topTint, bottomTint);
}

void AntControlLook::DrawMenuFieldFrame(BView *view, BRect &rect,
                                        const BRect &updateRect,
                                        const rgb_color &base,
                                        const rgb_color &background,
                                        uint32 flags, uint32 borders) {
  _DrawButtonFrame(view, rect, updateRect, kRadius, kRadius, kRadius, kRadius,
                   base, background, 1.0, 1.0, flags, borders);
}

void AntControlLook::DrawMenuFieldFrame(BView *view, BRect &rect,
                                        const BRect &updateRect, float radius,
                                        const rgb_color &base,
                                        const rgb_color &background,
                                        uint32 flags, uint32 borders) {
  _DrawButtonFrame(view, rect, updateRect, radius, radius, radius, radius, base,
                   background, 1.0, 1.0, flags, borders);
}

void AntControlLook::DrawMenuFieldFrame(
    BView *view, BRect &rect, const BRect &updateRect, float leftTopRadius,
    float rightTopRadius, float leftBottomRadius, float rightBottomRadius,
    const rgb_color &base, const rgb_color &background, uint32 flags,
    uint32 borders) {
  _DrawButtonFrame(view, rect, updateRect, leftTopRadius, rightTopRadius,
                   leftBottomRadius, rightBottomRadius, base, background, 1.0,
                   1.0, flags, borders);
}

// 绘制菜单字段背景的基础方法
// 实现Ant Design风格的菜单字段背景，具有扁平化设计和悬停效果
// 参数:
//   view - 绘制目标视图
//   rect - 菜单字段矩形区域(会被修改)
//   updateRect - 需要更新的区域
//   base - 基础颜色
//   flags - 状态标志(B_DISABLED禁用状态, B_HOVER悬停状态等)
//   borders - 需要绘制的边框(B_LEFT_BORDER等)
void AntControlLook::DrawMenuFieldBackground(BView *view, BRect &rect,
                                             const BRect &updateRect,
                                             const rgb_color &base,
                                             uint32 flags, uint32 borders) {
  // Ant Design菜单字段使用扁平背景和微妙的悬停效果
  float radius = kRadius;  // 使用默认圆角半径

  // 调用内部实现方法绘制外部背景
  // 参数说明:
  //   radius - 四个角的圆角半径(统一使用相同值)
  //   false - 不显示弹出指示器
  _DrawMenuFieldBackgroundOutside(view, rect, updateRect, radius, radius,
                                  radius, radius, base, false, flags, borders);
}

void AntControlLook::DrawMenuFieldBackground(BView *view, BRect &rect,
                                             const BRect &updateRect,
                                             float radius,
                                             const rgb_color &base,
                                             uint32 flags, uint32 borders) {
  _DrawMenuFieldBackgroundOutside(view, rect, updateRect, radius, radius,
                                  radius, radius, base, false, flags, borders);
}

void AntControlLook::DrawMenuFieldBackground(
    BView *view, BRect &rect, const BRect &updateRect, float leftTopRadius,
    float rightTopRadius, float leftBottomRadius, float rightBottomRadius,
    const rgb_color &base, uint32 flags, uint32 borders) {
  _DrawMenuFieldBackgroundOutside(
      view, rect, updateRect, leftTopRadius, rightTopRadius, leftBottomRadius,
      rightBottomRadius, base, false, flags, borders);
}

// 绘制菜单背景
// 实现Ant Design风格的菜单背景，具有扁平化设计和微妙的阴影效果
// 参数:
//   view - 绘制目标视图
//   rect - 菜单矩形区域(会被修改)
//   updateRect - 需要更新的区域
//   base - 基础颜色
//   flags - 状态标志(B_DISABLED禁用状态等)
//   borders - 需要绘制的边框(B_LEFT_BORDER等)
void AntControlLook::DrawMenuBackground(BView *view, BRect &rect,
                                        const BRect &updateRect,
                                        const rgb_color &base, uint32 flags,
                                        uint32 borders) {
  // 检查是否需要绘制，避免不必要的绘制操作
  if (!ShouldDraw(view, rect, updateRect)) return;

  // Ant Design菜单使用扁平白色背景和微妙的阴影效果
  // 将基础颜色调亮1级作为背景色
  rgb_color background = tint_color(base, B_LIGHTEN_1_TINT);

  // 设置背景色并填充整个矩形区域
  view->SetHighColor(background);
  view->FillRect(rect);

  // 绘制微妙的边框效果
  // 通过调整矩形边界来创建内边距效果
  if ((borders & B_LEFT_BORDER) != 0) rect.left++;    // 左边框内缩1像素
  if ((borders & B_TOP_BORDER) != 0) rect.top++;      // 上边框内缩1像素
  if ((borders & B_RIGHT_BORDER) != 0) rect.right--;  // 右边框内缩1像素
  if ((borders & B_BOTTOM_BORDER) != 0) rect.bottom--;  // 下边框内缩1像素
}

// 绘制菜单项背景
// 实现Ant Design风格的菜单项背景，具有悬停和选中状态效果
// 参数:
//   view - 绘制目标视图
//   rect - 菜单项矩形区域(会被修改)
//   updateRect - 需要更新的区域
//   base - 基础颜色
//   flags - 状态标志(B_DISABLED禁用状态, B_ACTIVATED选中状态,
//   B_HOVER悬停状态等) borders - 需要绘制的边框(B_LEFT_BORDER等)
void AntControlLook::DrawMenuItemBackground(BView *view, BRect &rect,
                                            const BRect &updateRect,
                                            const rgb_color &base, uint32 flags,
                                            uint32 borders) {
  // 检查是否需要绘制，避免不必要的绘制操作
  if (!ShouldDraw(view, rect, updateRect)) return;

  // Ant Design菜单项使用微妙的悬停和选中效果
  rgb_color background = base;  // 默认使用基础颜色

  // 根据状态确定背景颜色
  if ((flags & BControlLook::B_DISABLED) != 0) {
    // 禁用状态 - 使用非常微妙的半透明背景
    background = tint_color(base, B_LIGHTEN_2_TINT);
    background.alpha = 40;  // 40%透明度
  } else if ((flags & BControlLook::B_ACTIVATED) != 0) {
    // 选中/激活状态 - 使用主色并带有透明度
    background = tint_color(kAntPrimaryColor, B_LIGHTEN_1_TINT);
    background.alpha = 180;  // 70%透明度
  } else if ((flags & BControlLook::B_HOVER) != 0) {
    // 悬停状态 - 使用更浅的主色
    background = tint_color(kAntPrimaryColor, B_LIGHTEN_2_TINT);
    background.alpha = 80;  // 30%透明度
  }

  // 使用圆角矩形填充背景，符合Ant Design风格
  view->SetHighColor(background);
  view->FillRoundRect(rect, kRadius, kRadius);

  // 为选中状态的菜单项绘制微妙的边框
  if ((flags & B_ACTIVATED) != 0) {
    rgb_color borderColor = kAntPrimaryColor;
    borderColor.alpha = 200;  // 80%透明度
    view->SetHighColor(borderColor);
    view->StrokeRoundRect(rect, kRadius, kRadius);
  }
}

// 绘制边框
// 实现Ant Design风格的边框，具有微妙且扁平的设计
// 参数:
//   view - 绘制目标视图
//   rect - 边框矩形区域(会被修改)
//   updateRect - 需要更新的区域
//   base - 基础颜色
//   borderStyle - 边框样式(B_FANCY_BORDER花式边框/B_PLAIN_BORDER普通边框)
//   flags - 状态标志
//   borders - 需要绘制的边框(B_LEFT_BORDER等)
void AntControlLook::DrawBorder(BView *view, BRect &rect,
                                const BRect &updateRect, const rgb_color &base,
                                border_style borderStyle, uint32 flags,
                                uint32 borders) {
  // 检查是否需要绘制，避免不必要的绘制操作
  if (!ShouldDraw(view, rect, updateRect)) return;

  // 根据边框样式确定边框颜色
  rgb_color borderColor;
  switch (borderStyle) {
    case B_FANCY_BORDER:
      // 花式边框 - 使用更深的颜色
      borderColor = tint_color(base, B_DARKEN_2_TINT);
      break;
    case B_PLAIN_BORDER:
      // 普通边框 - 使用中等深度的颜色
      borderColor = tint_color(base, B_DARKEN_1_TINT);
      break;
    default:
      // 默认情况 - 使用与普通边框相同的颜色
      borderColor = tint_color(base, B_DARKEN_1_TINT);
      break;
  }

  // 设置边框颜色并绘制圆角矩形边框
  view->SetHighColor(borderColor);
  view->StrokeRoundRect(rect, kRadius, kRadius);

  // 调整矩形区域，为内容创建内边距
  // 通过将矩形向内收缩1像素来创建内容区域
  rect.InsetBy(1, 1);
}

// 绘制凸起边框
// 实现Ant Design风格的凸起边框效果，虽然Ant Design通常不使用凸起边框，
// 但此方法提供了一个微妙的替代方案
// 参数:
//   view - 绘制目标视图
//   rect - 边框矩形区域(会被修改)
//   updateRect - 需要更新的区域
//   base - 基础颜色
//   flags - 状态标志(B_DISABLED禁用状态等)
//   borders - 需要绘制的边框(B_LEFT_BORDER等)
void AntControlLook::DrawRaisedBorder(BView *view, BRect &rect,
                                      const BRect &updateRect,
                                      const rgb_color &base, uint32 flags,
                                      uint32 borders) {
  // 检查是否需要绘制，避免不必要的绘制操作
  if (!ShouldDraw(view, rect, updateRect)) return;

  // Ant Design不使用凸起边框，这里实现一个微妙的替代方案
  // 使用基础颜色调暗1级作为边框颜色
  rgb_color borderColor = tint_color(base, B_DARKEN_1_TINT);

  // 设置边框颜色并绘制圆角矩形边框
  view->SetHighColor(borderColor);
  view->StrokeRoundRect(rect, kRadius, kRadius);

  // 调整矩形区域，为内容创建内边距
  // 通过将矩形向内收缩1像素来创建内容区域
  rect.InsetBy(1, 1);
}

// 绘制文本控件边框
// 实现Ant Design风格的文本控件边框，具有扁平化设计和焦点高亮效果
// 参数:
//   view - 绘制目标视图
//   rect - 文本控件的矩形区域(会被修改)
//   updateRect - 需要更新的区域
//   base - 基础颜色
//   flags - 状态标志(B_DISABLED禁用状态, B_FOCUSED焦点状态等)
//   borders - 需要绘制的边框(B_LEFT_BORDER等)
void AntControlLook::DrawTextControlBorder(BView *view, BRect &rect,
                                           const BRect &updateRect,
                                           const rgb_color &base, uint32 flags,
                                           uint32 borders) {
  // 检查是否需要绘制，避免不必要的绘制操作
  if (!ShouldDraw(view, rect, updateRect)) return;

  // 根据控件状态确定边框颜色
  rgb_color borderColor;
  if ((flags & BControlLook::B_FOCUSED) != 0)
    // 焦点状态 - 使用Ant Design主色
    borderColor = kAntPrimaryColor;
  else if ((flags & BControlLook::B_DISABLED) != 0)
    // 禁用状态 - 使用基础颜色调暗1级
    borderColor = tint_color(base, B_DARKEN_1_TINT);
  else
    // 默认状态 - 使用基础颜色调暗2级
    borderColor = tint_color(base, B_DARKEN_2_TINT);

  // 设置边框颜色并绘制圆角矩形边框
  view->SetHighColor(borderColor);
  view->StrokeRoundRect(rect, kRadius, kRadius);

  // 调整矩形区域，为内容创建内边距
  // 通过将矩形向内收缩1像素来创建内容区域
  rect.InsetBy(1, 1);
}

// 绘制组框边框
// 实现Ant Design风格的组框边框，具有微妙圆角的设计
// 参数:
//   view - 绘制目标视图
//   rect - 组框的矩形区域(会被修改)
//   updateRect - 需要更新的区域
//   base - 基础颜色
//   borders - 需要绘制的边框(B_LEFT_BORDER等)
void AntControlLook::DrawGroupFrame(BView *view, BRect &rect,
                                    const BRect &updateRect,
                                    const rgb_color &base, uint32 borders) {
  // 检查是否需要绘制，避免不必要的绘制操作
  if (!ShouldDraw(view, rect, updateRect)) return;

  // Ant Design组框使用基础颜色调暗1级作为边框颜色
  // 这种设计比普通边框更微妙，符合Ant Design的扁平化风格
  rgb_color borderColor = tint_color(base, B_DARKEN_1_TINT);

  // 设置边框颜色并绘制圆角矩形边框
  // 使用默认圆角半径kRadius(6.0f)来保持Ant Design的统一风格
  view->SetHighColor(borderColor);
  view->StrokeRoundRect(rect, kRadius, kRadius);

  // 调整矩形区域，为内容创建内边距
  // 通过将矩形向内收缩1像素来创建内容区域
  // 这种内边距处理方式与Ant Design的其他组件保持一致
  rect.InsetBy(1, 1);
}

void AntControlLook::DrawButtonWithPopUpBackground(BView *view, BRect &rect,
                                                   const BRect &updateRect,
                                                   const rgb_color &base,
                                                   uint32 flags, uint32 borders,
                                                   orientation orientation) {
  _DrawButtonBackground(view, rect, updateRect, kRadius, kRadius, kRadius,
                        kRadius, base, true, flags, borders, orientation);
}

void AntControlLook::DrawButtonWithPopUpBackground(BView *view, BRect &rect,
                                                   const BRect &updateRect,
                                                   float radius,
                                                   const rgb_color &base,
                                                   uint32 flags, uint32 borders,
                                                   orientation orientation) {
  _DrawButtonBackground(view, rect, updateRect, radius, radius, radius, radius,
                        base, true, flags, borders, orientation);
}

void AntControlLook::DrawButtonWithPopUpBackground(
    BView *view, BRect &rect, const BRect &updateRect, float leftTopRadius,
    float rightTopRadius, float leftBottomRadius, float rightBottomRadius,
    const rgb_color &base, uint32 flags, uint32 borders,
    orientation orientation) {
  _DrawButtonBackground(view, rect, updateRect, leftTopRadius, rightTopRadius,
                        leftBottomRadius, rightBottomRadius, base, true, flags,
                        borders, orientation);
}

// #pragma mark - Private methods

// 绘制按钮边框的内部实现方法
// 实现Ant Design风格的按钮边框效果，包括不同状态下的颜色变化
// 参数:
//   view - 绘制目标视图
//   rect - 按钮矩形区域(会被修改)
//   updateRect - 需要更新的区域
//   leftTopRadius - 左上角圆角半径
//   rightTopRadius - 右上角圆角半径
//   leftBottomRadius - 左下角圆角半径
//   rightBottomRadius - 右下角圆角半径
//   base - 基础颜色
//   background - 背景颜色(未使用)
//   contrast - 对比度参数(未使用)
//   brightness - 亮度参数(未使用)
//   flags - 状态标志(B_DISABLED禁用状态, B_ACTIVATED激活状态,
//   B_HOVER悬停状态等) borders - 需要绘制的边框(B_LEFT_BORDER等)
void AntControlLook::_DrawButtonFrame(
    BView *view, BRect &rect, const BRect &updateRect, float leftTopRadius,
    float rightTopRadius, float leftBottomRadius, float rightBottomRadius,
    const rgb_color &base, const rgb_color &background, float contrast,
    float brightness, uint32 flags, uint32 borders) {
  // 检查是否需要绘制，避免不必要的绘制操作
  if (!ShouldDraw(view, rect, updateRect)) return;

  // 根据按钮状态确定边框颜色
  rgb_color borderColor;
  if ((flags & BControlLook::B_DISABLED) != 0)
    // 禁用状态 - 使用基础颜色调暗1级
    borderColor = tint_color(base, B_DARKEN_1_TINT);
  else if ((flags & BControlLook::B_ACTIVATED) != 0)
    // 激活/按下状态 - 使用Ant Design主色
    borderColor = kAntPrimaryColor;
  else if ((flags & BControlLook::B_HOVER) != 0)
    // 悬停状态 - 使用主色调亮1级
    borderColor = tint_color(kAntPrimaryColor, B_LIGHTEN_1_TINT);
  else
    // 默认状态 - 使用基础颜色调暗2级
    borderColor = tint_color(base, B_DARKEN_2_TINT);

  // 设置边框颜色并绘制圆角矩形边框
  view->SetHighColor(borderColor);
  view->StrokeRoundRect(rect, leftTopRadius, leftTopRadius);

  // 调整矩形区域，为内容创建内边距
  // 通过将矩形向内收缩1像素来创建内容区域
  rect.InsetBy(1, 1);
}

// 绘制凹陷外框的内部实现方法
// 虽然Ant Design通常不使用凹陷效果，但此方法提供了一个微妙的替代方案
// 参数:
//   view - 绘制目标视图
//   rect - 矩形区域(会被修改)
//   base - 基础颜色
//   contrast - 对比度参数(未使用)
//   brightness - 亮度参数(未使用)
//   flags - 状态标志(未使用)
//   borders - 需要绘制的边框(未使用)
void AntControlLook::_DrawOuterResessedFrame(BView *view, BRect &rect,
                                             const rgb_color &base,
                                             float contrast, float brightness,
                                             uint32 flags, uint32 borders) {
  // Ant Design不使用凹陷边框，这里实现一个微妙的替代方案
  // 使用基础颜色调暗1级作为边框颜色
  rgb_color borderColor = tint_color(base, B_DARKEN_1_TINT);

  // 设置边框颜色并绘制圆角矩形边框
  // 使用默认圆角半径kRadius(6.0f)保持Ant Design的统一风格
  view->SetHighColor(borderColor);
  view->StrokeRoundRect(rect, kRadius, kRadius);

  // 调整矩形区域，为内容创建内边距
  // 通过将矩形向内收缩1像素来创建内容区域
  // 这种内边距处理方式与Ant Design的其他组件保持一致
  rect.InsetBy(1, 1);
}

void AntControlLook::_DrawButtonBackground(
    BView *view, BRect &rect, const BRect &updateRect, float leftTopRadius,
    float rightTopRadius, float leftBottomRadius, float rightBottomRadius,
    const rgb_color &base, bool popupIndicator, uint32 flags, uint32 borders,
    orientation orientation) {
  // Ant Design buttons have flat backgrounds with hover and active states
  if (!ShouldDraw(view, rect, updateRect)) return;

  rgb_color backgroundColor;
  if ((flags & BControlLook::B_DISABLED) != 0)
    backgroundColor = tint_color(base, B_LIGHTEN_2_TINT);
  else if ((flags & BControlLook::B_ACTIVATED) != 0)
    backgroundColor = tint_color(kAntPrimaryColor, B_LIGHTEN_1_TINT);
  else if ((flags & BControlLook::B_HOVER) != 0)
    backgroundColor = tint_color(base, B_LIGHTEN_1_TINT);
  else
    backgroundColor = base;

  view->SetHighColor(backgroundColor);
  view->FillRoundRect(rect, leftTopRadius, leftTopRadius);

  // Draw popup indicator if needed
  if (popupIndicator) _DrawPopUpMarker(view, rect, base, flags);
}

void AntControlLook::_DrawNonFlatButtonBackground(
    BView *view, BRect &rect, const BRect &updateRect, float leftTopRadius,
    float rightTopRadius, float leftBottomRadius, float rightBottomRadius,
    const rgb_color &base, bool popupIndicator, uint32 flags, uint32 borders,
    orientation orientation) {
  // Ant Design 不使用非平面按钮，但我们将实现一个微妙的版本
  _DrawButtonBackground(view, rect, updateRect, leftTopRadius, rightTopRadius,
                        leftBottomRadius, rightBottomRadius, base,
                        popupIndicator, flags, borders, orientation);
}

// 绘制弹出菜单指示器(向下箭头)的内部实现方法
// 实现Ant Design风格的弹出菜单指示器，具有不同状态下的颜色变化
// 参数:
//   view - 绘制目标视图
//   rect - 按钮的矩形区域
//   base - 基础颜色
//   flags - 状态标志(B_DISABLED禁用状态等)
void AntControlLook::_DrawPopUpMarker(BView *view, const BRect &rect,
                                      const rgb_color &base, uint32 flags) {
  // 根据状态确定箭头颜色
  rgb_color arrowColor;
  if ((flags & BControlLook::B_DISABLED) != 0)
    // 禁用状态 - 使用基础颜色调暗2级
    arrowColor = tint_color(base, B_DARKEN_2_TINT);
  else
    // 正常状态 - 使用基础颜色调暗4级(更深的颜色)
    arrowColor = tint_color(base, B_DARKEN_4_TINT);

  // 设置箭头颜色
  view->SetHighColor(arrowColor);

  // 计算箭头位置
  // 从按钮右侧向内偏移指示器宽度的一半再加8像素
  float centerX = rect.right - kButtonPopUpIndicatorWidth / 2 - 8;
  // 垂直居中
  float centerY = rect.top + rect.Height() / 2;

  // 绘制向下箭头(三角形)
  BPoint points[3];
  points[0] = BPoint(centerX - 4, centerY - 2);  // 左上点
  points[1] = BPoint(centerX, centerY + 2);      // 下中点
  points[2] = BPoint(centerX + 4, centerY - 2);  // 右上点
  view->FillTriangle(points[0], points[1], points[2]);
}

void AntControlLook::_DrawMenuFieldBackgroundOutside(
    BView *view, BRect &rect, const BRect &updateRect, float leftTopRadius,
    float rightTopRadius, float leftBottomRadius, float rightBottomRadius,
    const rgb_color &base, bool popupIndicator, uint32 flags, uint32 borders) {
  // Ant Design menu fields have flat backgrounds with hover effects
  if (!ShouldDraw(view, rect, updateRect)) return;

  rgb_color backgroundColor;
  if ((flags & BControlLook::B_DISABLED) != 0)
    backgroundColor = tint_color(base, B_LIGHTEN_2_TINT);
  else if ((flags & BControlLook::B_ACTIVATED) != 0)
    backgroundColor = tint_color(base, B_LIGHTEN_1_TINT);
  else if ((flags & BControlLook::B_HOVER) != 0)
    backgroundColor = tint_color(base, B_LIGHTEN_1_TINT);
  else
    backgroundColor = base;

  view->SetHighColor(backgroundColor);
  view->FillRoundRect(rect, leftTopRadius, leftTopRadius);

  // Draw popup indicator if needed
  if (popupIndicator) _DrawPopUpMarker(view, rect, base, flags);
}

void AntControlLook::_DrawMenuFieldBackgroundInside(
    BView *view, BRect &rect, const BRect &updateRect, float leftTopRadius,
    float rightTopRadius, float leftBottomRadius, float rightBottomRadius,
    const rgb_color &base, bool popupIndicator, uint32 flags, uint32 borders) {
  // Similar to outside but for the inside part
  _DrawMenuFieldBackgroundOutside(
      view, rect, updateRect, leftTopRadius, rightTopRadius, leftBottomRadius,
      rightBottomRadius, base, popupIndicator, flags, borders);
}

rgb_color AntControlLook::_EdgeLightColor(const rgb_color &base, float contrast,
                                          float brightness, uint32 flags) {
  return tint_color(base, B_LIGHTEN_1_TINT);
}

rgb_color AntControlLook::_EdgeShadowColor(const rgb_color &base,
                                           float contrast, float brightness,
                                           uint32 flags) {
  return tint_color(base, B_DARKEN_1_TINT);
}

rgb_color AntControlLook::_BevelLightColor(const rgb_color &base,
                                           uint32 flags) {
  return tint_color(base, B_LIGHTEN_1_TINT);
}

rgb_color AntControlLook::_BevelShadowColor(const rgb_color &base,
                                            uint32 flags) {
  return tint_color(base, B_DARKEN_1_TINT);
}

void AntControlLook::_MakeGradient(BGradientLinear &gradient, const BRect &rect,
                                   const rgb_color &base, float topTint,
                                   float bottomTint,
                                   orientation orientation) const {
  // Ant Design doesn't use gradients, but we'll implement a subtle version
  gradient.AddColor(tint_color(base, topTint), 0);
  gradient.AddColor(tint_color(base, bottomTint), 255);

  if (orientation == B_HORIZONTAL)
    gradient.SetStart(rect.LeftTop());
  else
    gradient.SetStart(rect.LeftBottom());

  if (orientation == B_HORIZONTAL)
    gradient.SetEnd(rect.RightTop());
  else
    gradient.SetEnd(rect.LeftTop());
}

void AntControlLook::_MakeGlossyGradient(BGradientLinear &gradient,
                                         const BRect &rect,
                                         const rgb_color &base, float topTint,
                                         float bottomTint,
                                         orientation orientation) const {
  // Ant Design doesn't use glossy gradients, use flat colors instead
  _MakeGradient(gradient, rect, base, topTint, bottomTint, orientation);
}

void AntControlLook::_MakeButtonGradient(BGradientLinear &gradient, BRect &rect,
                                         const rgb_color &base, uint32 flags,
                                         orientation orientation) const {
  // Ant Design buttons don't use gradients, use flat colors instead
  float topTint = 1.0;
  float bottomTint = 1.0;

  if ((flags & BControlLook::B_ACTIVATED) != 0) {
    // Use primary color for activated buttons
    _MakeGradient(gradient, rect, kAntPrimaryColor, topTint, bottomTint,
                  orientation);
  } else if ((flags & BControlLook::B_HOVER) != 0) {
    // Use lighter primary color for hovered buttons
    _MakeGradient(gradient, rect,
                  tint_color(kAntPrimaryColor, B_LIGHTEN_1_TINT), topTint,
                  bottomTint, orientation);
  } else {
    // Use base color for normal buttons
    _MakeGradient(gradient, rect, base, topTint, bottomTint, orientation);
  }
}

void AntControlLook::DrawScrollBarBorder(BView *view, BRect rect,
                                         const BRect &updateRect,
                                         const rgb_color &base, uint32 flags,
                                         orientation orientation) {
  if (!ShouldDraw(view, rect, updateRect)) return;

  view->PushState();

  // Ant Design风格滚动条边框 - 仅在悬停或激活时显示非常微妙的边框
  bool isEnabled = (flags & B_DISABLED) == 0;
  bool isHovered = (flags & B_HOVER) != 0;
  bool isActivated = (flags & B_ACTIVATED) != 0;

  if (isEnabled && (isHovered || isActivated)) {
    // 使用非常微妙的半透明边框
    rgb_color borderColor = tint_color(base, B_DARKEN_1_TINT);
    borderColor.alpha = 40;  // 非常透明的边框

    view->SetHighColor(borderColor);

    // 根据滚动条方向绘制边框
    if (orientation == B_HORIZONTAL) {
      // 水平滚动条 - 只绘制顶部和底部边框
      view->StrokeLine(rect.LeftTop(), rect.RightTop());
      view->StrokeLine(rect.LeftBottom(), rect.RightBottom());
    } else {
      // 垂直滚动条 - 只绘制左侧和右侧边框
      view->StrokeLine(rect.LeftTop(), rect.LeftBottom());
      view->StrokeLine(rect.RightTop(), rect.RightBottom());
    }
  }

  view->PopState();
}

void AntControlLook::DrawScrollBarButton(BView *view, BRect rect,
                                         const BRect &updateRect,
                                         const rgb_color &base, uint32 flags,
                                         int32 direction,
                                         orientation orientation, bool down) {
  // Ant Design 5.0
  // 滚动条通常没有可见的按钮，但为了兼容性，我们将实现最小化的按钮。
  if (!ShouldDraw(view, rect, updateRect)) return;

  // Ant Design uses more subtle, rounded buttons with minimal visual presence
  rgb_color background;
  if ((flags & BControlLook::B_DISABLED) != 0) {
    background = tint_color(base, B_LIGHTEN_2_TINT);
    background.alpha = 80;  // More transparent when disabled
  } else if (down) {
    background = tint_color(kAntPrimaryColor, B_LIGHTEN_1_TINT);
    background.alpha = 180;  // Semi-transparent when pressed
  } else if ((flags & BControlLook::B_HOVER) != 0) {
    background = tint_color(base, B_LIGHTEN_1_TINT);
    background.alpha = 120;  // Semi-transparent on hover
  } else {
    background = base;
    background.alpha = 40;  // Very transparent when not interacting
  }

  // Make buttons slightly rounded for Ant Design style
  view->SetHighColor(background);
  view->FillRoundRect(rect, kRadius, kRadius);

  // Draw arrow with more subtle styling
  rgb_color arrowColor;
  if ((flags & B_DISABLED) != 0) {
    arrowColor = tint_color(base, B_DARKEN_2_TINT);
    arrowColor.alpha = 120;  // Semi-transparent when disabled
  } else if (down || (flags & B_HOVER) != 0) {
    arrowColor = kAntPrimaryColor;
    arrowColor.alpha = 220;  // More visible on interaction
  } else {
    arrowColor =
        tint_color(base, B_DARKEN_3_TINT);  // Less contrast for Ant Design
    arrowColor.alpha = 180;  // Semi-transparent when not interacting
  }

  view->SetHighColor(arrowColor);

  // Calculate arrow position - slightly smaller for Ant Design
  float arrowSize =
      min_c(rect.Width(), rect.Height()) / 4.0f;  // Even smaller arrows
  BRect arrowRect(rect);

  // Adjust arrow position based on direction
  switch (direction) {
    case B_LEFT_ARROW:
    case B_RIGHT_ARROW:
    case B_UP_ARROW:
    case B_DOWN_ARROW:
      // Center the arrow
      arrowRect.InsetBy((rect.Width() - arrowSize) / 2.0f,
                        (rect.Height() - arrowSize) / 2.0f);
      break;
  }

  // Draw the arrow with slightly thinner lines for Ant Design
  switch (direction) {
    case B_LEFT_ARROW: {
      BPoint points[3];
      points[0] = BPoint(arrowRect.right, arrowRect.top);
      points[1] =
          BPoint(arrowRect.left, (arrowRect.top + arrowRect.bottom) / 2.0f);
      points[2] = BPoint(arrowRect.right, arrowRect.bottom);
      view->FillTriangle(points[0], points[1], points[2]);
      break;
    }

    case B_RIGHT_ARROW: {
      BPoint points[3];
      points[0] = BPoint(arrowRect.left, arrowRect.top);
      points[1] =
          BPoint(arrowRect.right, (arrowRect.top + arrowRect.bottom) / 2.0f);
      points[2] = BPoint(arrowRect.left, arrowRect.bottom);
      view->FillTriangle(points[0], points[1], points[2]);
      break;
    }

    case B_UP_ARROW: {
      BPoint points[3];
      points[0] = BPoint(arrowRect.left, arrowRect.bottom);
      points[1] =
          BPoint((arrowRect.left + arrowRect.right) / 2.0f, arrowRect.top);
      points[2] = BPoint(arrowRect.right, arrowRect.bottom);
      view->FillTriangle(points[0], points[1], points[2]);
      break;
    }

    case B_DOWN_ARROW: {
      BPoint points[3];
      points[0] = BPoint(arrowRect.left, arrowRect.top);
      points[1] =
          BPoint((arrowRect.left + arrowRect.right) / 2.0f, arrowRect.bottom);
      points[2] = BPoint(arrowRect.right, arrowRect.top);
      view->FillTriangle(points[0], points[1], points[2]);
      break;
    }
  }

  // Add subtle highlight effect for depth when interacting
  if ((flags & BControlLook::B_DISABLED) == 0 &&
      (down || (flags & BControlLook::B_HOVER) != 0)) {
    rgb_color highlightColor = {255, 255, 255,
                                20};  // Very subtle white highlight
    view->SetHighColor(highlightColor);

    BRect highlightRect = rect;
    highlightRect.InsetBy(1.0f, 1.0f);
    highlightRect.bottom = (rect.top + rect.bottom) / 2.0f;

    view->FillRoundRect(highlightRect, kRadius, kRadius);
  }
}

void AntControlLook::DrawScrollBarBackground(
    BView *view, BRect &rect1, BRect &rect2, const BRect &updateRect,
    const rgb_color &base, uint32 flags, orientation orientation) {
  DrawScrollBarBackground(view, rect1, updateRect, base, flags, orientation);
  DrawScrollBarBackground(view, rect2, updateRect, base, flags, orientation);
}

void AntControlLook::DrawScrollBarBackground(BView *view, BRect &rect,
                                             const BRect &updateRect,
                                             const rgb_color &base,
                                             uint32 flags,
                                             orientation orientation) {
  // Ant Design 5.0 scrollbars have minimal, flat backgrounds that only appear
  // on hover
  if (!ShouldDraw(view, rect, updateRect)) return;

  // Make scrollbar track even thinner for Ant Design 5.0 style
  if (orientation == B_HORIZONTAL) {
    float centerY = (rect.top + rect.bottom) / 2;
    rect.top = centerY - 2;  // Thinner track (4px total height)
    rect.bottom = centerY + 2;
  } else {
    float centerX = (rect.left + rect.right) / 2;
    rect.left = centerX - 2;  // Thinner track (4px total width)
    rect.right = centerX + 2;
  }

  // Ant Design 5.0 使用非常微妙、半透明的滚动条轨道，在悬停之前几乎不可见。
  rgb_color background;
  if ((flags & BControlLook::B_DISABLED) != 0) {
    background = tint_color(base, B_LIGHTEN_1_TINT);
    background.alpha = 20;  // Almost invisible when disabled
  } else if ((flags & BControlLook::B_HOVER) != 0 ||
             (flags & BControlLook::B_ACTIVATED) != 0) {
    background = tint_color(base, B_DARKEN_1_TINT);
    background.alpha = 40;  // Slightly more visible on hover/active
  } else {
    background = tint_color(base, B_LIGHTEN_1_TINT);
    background.alpha = 25;  // Very subtle transparency for normal state
  }

  view->SetHighColor(background);
  view->FillRoundRect(rect, kRadius, kRadius);

  // Add subtle inner shadow effect only when hovered or activated
  if ((flags & BControlLook::B_DISABLED) == 0 &&
      ((flags & BControlLook::B_HOVER) != 0 ||
       (flags & BControlLook::B_ACTIVATED) != 0)) {
    rgb_color shadowColor = tint_color(base, B_DARKEN_1_TINT);
    shadowColor.alpha = 20;  // Very subtle shadow
    view->SetHighColor(shadowColor);

    if (orientation == B_HORIZONTAL) {
      view->StrokeLine(BPoint(rect.left + kRadius, rect.bottom - 0.5f),
                       BPoint(rect.right - kRadius, rect.bottom - 0.5f));
    } else {
      view->StrokeLine(BPoint(rect.right - 0.5f, rect.top + kRadius),
                       BPoint(rect.right - 0.5f, rect.bottom - kRadius));
    }
  }

  // Add subtle highlight effect for depth when hovered or activated
  if ((flags & B_DISABLED) == 0 &&
      ((flags & B_HOVER) != 0 || (flags & B_ACTIVATED) != 0)) {
    rgb_color highlightColor = {255, 255, 255,
                                15};  // Very subtle white highlight
    view->SetHighColor(highlightColor);

    BRect highlightRect = rect;
    highlightRect.InsetBy(0.5f, 0.5f);

    if (orientation == B_HORIZONTAL) {
      highlightRect.bottom = (rect.top + rect.bottom) / 2.0f;
    } else {
      highlightRect.right = (rect.left + rect.right) / 2.0f;
    }

    view->FillRoundRect(highlightRect, kRadius, kRadius);
  }
}

void AntControlLook::DrawScrollBarThumb(BView *view, BRect &rect,
                                        const BRect &updateRect,
                                        const rgb_color &base, uint32 flags,
                                        orientation orientation) {
  // Ant Design 5.0 scrollbar thumbs are minimal, rounded and appear on demand
  if (!ShouldDraw(view, rect, updateRect)) return;

  // Make scrollbar thumb smaller and more rounded for Ant Design 5.0 style
  float centerX = (rect.left + rect.right) / 2;
  float centerY = (rect.top + rect.bottom) / 2;

  if (orientation == B_HORIZONTAL) {
    rect.top = centerY - 2;  // Thinner thumb (4px total height)
    rect.bottom = centerY + 2;

    // Make thumb shorter - Ant Design uses proportional thumbs
    float width = rect.Width() * 0.5f;  // Even shorter for Ant Design 5.0
    rect.left = centerX - width / 2;
    rect.right = centerX + width / 2;
  } else {
    rect.left = centerX - 2;  // Thinner thumb (4px total width)
    rect.right = centerX + 2;

    // Make thumb shorter - Ant Design uses proportional thumbs
    float height = rect.Height() * 0.5f;  // Even shorter for Ant Design 5.0
    rect.top = centerY - height / 2;
    rect.bottom = centerY + height / 2;
  }

  rgb_color thumbColor;
  if ((flags & B_DISABLED) != 0) {
    thumbColor = tint_color(base, B_LIGHTEN_2_TINT);
    thumbColor.alpha = 100;  // More transparent when disabled
  } else if ((flags & B_ACTIVATED) != 0) {
    thumbColor = kAntPrimaryColor;
    thumbColor.alpha = 230;  // Almost opaque when activated
  } else if ((flags & B_HOVER) != 0) {
    thumbColor = tint_color(kAntPrimaryColor, B_LIGHTEN_1_TINT);
    thumbColor.alpha = 200;  // More visible on hover
  } else {
    thumbColor = tint_color(base, B_DARKEN_3_TINT);
    thumbColor.alpha = 130;  // More transparent when not interacting
  }

  // Draw the thumb with more rounded corners
  view->SetHighColor(thumbColor);
  view->FillRoundRect(rect, kRadius, kRadius);

  // Add subtle highlight effect for depth when not disabled
  if ((flags & B_DISABLED) == 0 &&
      ((flags & B_ACTIVATED) != 0 || (flags & B_HOVER) != 0)) {
    rgb_color highlightColor = {255, 255, 255,
                                30};  // Very subtle white highlight
    view->SetHighColor(highlightColor);

    BRect highlightRect = rect;
    highlightRect.InsetBy(0.5f, 0.5f);

    if (orientation == B_HORIZONTAL) {
      highlightRect.bottom = centerY;
    } else {
      highlightRect.right = centerX;
    }

    view->FillRoundRect(highlightRect, kRadius, kRadius);
  }

  // Add subtle shadow effect for depth when activated
  if ((flags & B_DISABLED) == 0 && (flags & B_ACTIVATED) != 0) {
    rgb_color shadowColor = {0, 0, 0, 15};  // Very subtle shadow
    view->SetHighColor(shadowColor);

    BRect shadowRect = rect;
    shadowRect.InsetBy(0.5f, 0.5f);

    if (orientation == B_HORIZONTAL) {
      shadowRect.top = centerY;
    } else {
      shadowRect.left = centerX;
    }

    view->FillRoundRect(shadowRect, kRadius, kRadius);
  }
}

void AntControlLook::DrawScrollViewFrame(BView *view, BRect &rect,
                                         const BRect &updateRect,
                                         border_style borderStyle, uint32 flags,
                                         uint32 borders) {
  // Ant Design scroll views have subtle borders
  if (!ShouldDraw(view, rect, updateRect)) return;

  rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
  rgb_color borderColor = tint_color(base, B_DARKEN_1_TINT);

  view->SetHighColor(borderColor);
  view->StrokeRoundRect(rect, kRadius, kRadius);

  // Adjust the rectangle for content
  rect.InsetBy(1, 1);
}

rgb_color AntControlLook::SliderBarColor(const rgb_color &base) {
  // Ant Design 滑块使用主色
  return kAntPrimaryColor;
}

void AntControlLook::DrawSliderBar(BView *view, BRect rect,
                                   const BRect &updateRect,
                                   const rgb_color &base,
                                   rgb_color leftFillColor,
                                   rgb_color rightFillColor, uint32 flags,
                                   orientation orientation) {
  // Ant Design 5.0 滑块的轨道非常细，并且两端是圆角的
  if (!ShouldDraw(view, rect, updateRect)) return;

  // Make the bar even thinner for Ant Design 5.0 style
  if (orientation == B_HORIZONTAL) {
    float centerY = (rect.top + rect.bottom) / 2;
    rect.top = centerY - 1.5f;  // Thinner track (3px total height)
    rect.bottom = centerY + 1.5f;
  } else {
    float centerX = (rect.left + rect.right) / 2;
    rect.left = centerX - 1.5f;  // Thinner track (3px total width)
    rect.right = centerX + 1.5f;
  }

  // Draw background track with subtle transparency
  rgb_color backgroundColor = tint_color(base, B_LIGHTEN_2_TINT);
  backgroundColor.alpha = 180;  // Slight transparency for unfilled portion
  view->SetHighColor(backgroundColor);
  view->FillRoundRect(rect, kRadius, kRadius);

  // Calculate fill position based on flags
  float fillPosition = 0.5f;  // Default to middle

  // 在实际实现中，这将根据滑块的值进行计算
  // 目前，我们将使用一个固定位置进行演示

  // 使用主色绘制填充部分
  BRect fillRect = rect;
  if (orientation == B_HORIZONTAL) {
    fillRect.right = rect.left + (rect.right - rect.left) * fillPosition;

    // Ant Design 5.0 uses the primary color for the filled portion
    rgb_color fillColorAdjusted = leftFillColor;

    // Adjust color based on state
    if ((flags & BControlLook::B_DISABLED) != 0) {
      fillColorAdjusted = tint_color(fillColorAdjusted, B_LIGHTEN_1_TINT);
      fillColorAdjusted.alpha = 150;  // More transparent when disabled
    } else if ((flags & BControlLook::B_HOVER) != 0 ||
               (flags & BControlLook::B_ACTIVATED) != 0) {
      // Slightly brighter when hovered or activated
      fillColorAdjusted = tint_color(fillColorAdjusted, B_LIGHTEN_2_TINT);
    }

    view->SetHighColor(fillColorAdjusted);
    view->FillRoundRect(fillRect, kRadius, kRadius);
  } else {
    fillRect.top = rect.bottom - (rect.bottom - rect.top) * fillPosition;

    // Ant Design 5.0 使用主色填充部分区域
    rgb_color fillColorAdjusted = leftFillColor;

    // Adjust color based on state
    if ((flags & BControlLook::B_DISABLED) != 0) {
      fillColorAdjusted = tint_color(fillColorAdjusted, B_LIGHTEN_1_TINT);
      fillColorAdjusted.alpha = 150;  // 禁用时更加透明
    } else if ((flags & B_HOVER) != 0 ||
               (flags & BControlLook::B_ACTIVATED) != 0) {
      // 悬停或激活时稍微更亮
      fillColorAdjusted = tint_color(fillColorAdjusted, B_LIGHTEN_2_TINT);
    }

    view->SetHighColor(fillColorAdjusted);
    view->FillRoundRect(fillRect, kRadius, kRadius);
  }
}

void AntControlLook::DrawSliderBar(BView *view, BRect rect,
                                   const BRect &updateRect,
                                   const rgb_color &base, rgb_color fillColor,
                                   uint32 flags, orientation orientation) {
  // 使用单一填充颜色的简化版本
  DrawSliderBar(view, rect, updateRect, base, fillColor, fillColor, flags,
                orientation);
}

void AntControlLook::DrawSliderThumb(BView *view, BRect &rect,
                                     const BRect &updateRect,
                                     const rgb_color &base, uint32 flags,
                                     orientation orientation) {
  // Ant Design 滑块的滑块按钮是圆形的
  if (!ShouldDraw(view, rect, updateRect)) return;

  // 将滑块按钮设置为圆形
  float size = min_c(rect.Width(), rect.Height());
  float centerX = (rect.left + rect.right) / 2;
  float centerY = (rect.top + rect.bottom) / 2;

  // 调整矩形以形成一个完美的圆形
  rect.left = centerX - size / 2;
  rect.right = centerX + size / 2;
  rect.top = centerY - size / 2;
  rect.bottom = centerY + size / 2;

  // 根据状态确定颜色
  rgb_color thumbColor;
  rgb_color borderColor;

  if ((flags & B_DISABLED) != 0) {
    thumbColor = tint_color(base, B_LIGHTEN_2_TINT);
    borderColor = tint_color(base, B_LIGHTEN_1_TINT);
  } else if ((flags & B_ACTIVATED) != 0) {
    thumbColor = kAntPrimaryColor;
    borderColor = tint_color(kAntPrimaryColor, B_DARKEN_1_TINT);
  } else if ((flags & B_HOVER) != 0) {
    thumbColor = tint_color(kAntPrimaryColor, B_LIGHTEN_1_TINT);
    borderColor = kAntPrimaryColor;
  } else {
    thumbColor = ui_color(B_CONTROL_BACKGROUND_COLOR);
    borderColor = kAntPrimaryColor;
  }

  // Draw the thumb
  view->SetHighColor(thumbColor);
  view->FillEllipse(rect);

  // Add subtle shadow effect for depth
  if ((flags & BControlLook::B_DISABLED) == 0) {
    view->SetHighColor(255, 255, 255, 30);
    BRect highlightRect = rect;
    highlightRect.InsetBy(1, 1);
    highlightRect.bottom -= size / 2;
    view->FillEllipse(highlightRect);
  }

  // Draw border
  view->SetHighColor(borderColor);
  view->StrokeEllipse(rect);

  // Draw border
  view->SetHighColor(borderColor);
  view->StrokeEllipse(rect);
}

void AntControlLook::DrawActiveTab(BView *view, BRect &rect,
                                   const BRect &updateRect,
                                   const rgb_color &base, uint32 flags,
                                   uint32 borders, border_style borderStyle,
                                   uint32 side) {
  // Ant Design tabs have flat design with an accent line for active tabs
  if (!ShouldDraw(view, rect, updateRect)) return;

  // Fill tab background
  rgb_color background;
  if ((flags & BControlLook::B_DISABLED) != 0)
    background = tint_color(base, B_LIGHTEN_2_TINT);
  else if ((flags & B_HOVER) != 0 && (flags & BControlLook::B_ACTIVATED) == 0)
    background = tint_color(base, B_LIGHTEN_1_TINT);
  else
    background = base;

  view->SetHighColor(background);
  view->FillRect(rect);

  // Draw active indicator
  if ((flags & BControlLook::B_ACTIVATED) != 0) {
    view->SetHighColor(kAntPrimaryColor);

    // Draw indicator based on tab position
    switch (side) {
      case BControlLook::B_TOP_BORDER:
        view->FillRect(
            BRect(rect.left, rect.bottom - 2, rect.right, rect.bottom));
        break;
      case BControlLook::B_BOTTOM_BORDER:
        view->FillRect(BRect(rect.left, rect.top, rect.right, rect.top + 2));
        break;
      case BControlLook::B_LEFT_BORDER:
        view->FillRect(
            BRect(rect.right - 2, rect.top, rect.right, rect.bottom));
        break;
      case BControlLook::B_RIGHT_BORDER:
        view->FillRect(BRect(rect.left, rect.top, rect.left + 2, rect.bottom));
        break;
    }
  }
}

void AntControlLook::DrawInactiveTab(BView *view, BRect &rect,
                                     const BRect &updateRect,
                                     const rgb_color &base, uint32 flags,
                                     uint32 borders, uint32 side, int32 index,
                                     int32 selected, int32 first, int32 last) {
  // Ant Design inactive tabs are flat and subtle
  if (!ShouldDraw(view, rect, updateRect)) return;

  // Fill tab background with a more subtle color
  rgb_color background;
  if ((flags & BControlLook::B_DISABLED) != 0)
    background = tint_color(base, B_LIGHTEN_2_TINT);
  else if ((flags & BControlLook::B_HOVER) != 0)
    background = tint_color(base, B_LIGHTEN_1_TINT);
  else
    background =
        tint_color(base, B_NO_TINT);  // Use base color for inactive tabs

  // Make inactive tabs slightly transparent for Ant Design style
  background.alpha = 200;  // Slightly transparent

  view->SetHighColor(background);
  view->FillRect(rect);

  // Draw a subtle bottom border for inactive tabs
  rgb_color borderColor = tint_color(base, B_DARKEN_1_TINT);
  borderColor.alpha = 100;  // Very subtle border
  view->SetHighColor(borderColor);

  // Draw border based on tab position
  switch (side) {
    case BControlLook::B_TOP_BORDER:
      view->StrokeLine(BPoint(rect.left, rect.bottom),
                       BPoint(rect.right, rect.bottom));
      break;
    case BControlLook::B_BOTTOM_BORDER:
      view->StrokeLine(BPoint(rect.left, rect.top),
                       BPoint(rect.right, rect.top));
      break;
    case BControlLook::B_LEFT_BORDER:
      view->StrokeLine(BPoint(rect.right, rect.top),
                       BPoint(rect.right, rect.bottom));
      break;
    case BControlLook::B_RIGHT_BORDER:
      view->StrokeLine(BPoint(rect.left, rect.top),
                       BPoint(rect.left, rect.bottom));
      break;
  }
}

void AntControlLook::DrawSplitter(BView *view, BRect &rect,
                                  const BRect &updateRect,
                                  const rgb_color &base,
                                  orientation orientation, uint32 flags,
                                  uint32 borders) {
  // Ant Design splitters are subtle
  if (!ShouldDraw(view, rect, updateRect)) return;

  // Fill background
  rgb_color background = base;
  view->SetHighColor(background);
  view->FillRect(rect);

  // Draw divider line
  rgb_color dividerColor = tint_color(base, B_DARKEN_1_TINT);
  view->SetHighColor(dividerColor);

  if (orientation == B_HORIZONTAL) {
    // Horizontal splitter - draw vertical line
    float center = (rect.left + rect.right) / 2;
    view->StrokeLine(BPoint(center, rect.top), BPoint(center, rect.bottom));
  } else {
    // Vertical splitter - draw horizontal line
    float center = (rect.top + rect.bottom) / 2;
    view->StrokeLine(BPoint(rect.left, center), BPoint(rect.right, center));
  }
}
}  // namespace BPrivate

extern "C" BControlLook *instantiate_control_look(image_id id) {
  return new (std::nothrow) BPrivate::AntControlLook();
}